/*
 * Copyright (C) 2010-2011 Comcast Cable.  All Rights Reserved.
 */
package com.hercules.android.receiver.model.objects;

import android.graphics.Color;
import android.graphics.Paint;

import com.hercules.android.receiver.painting.PaintersUtil;

/**
 * <p>
 * This class represents resources that are used to display strings of text. It is a simple JavaBean (POJO) that
 * provides getters and setters for all private attributes and performs no argument validation in the setters.
 * </p>
 * <p>
 * <strong>Thread safety:</strong> This class is mutable and not thread safe.
 * </p>
 *
 * @author saarixx, jmn
 * @version 1.0
 */
public class XREText extends XREResource {

    /**
     * <p>
     * Represents default text size in pixels.
     * </p>
     */
    private static final int DEFAULT_TEXT_SIZE = 12;

    /**
     * <p>
     * The text to be displayed by the resource. Defaults to an empty string.
     * </p>
     * <p>
     * Can be any value.
     * </p>
     * <p>
     * Has getter and setter.
     * </p>
     */
    private String text = "";

    /**
     * <p>
     * The font resource to be used to display the text. If omitted, the default font will be used.
     * </p>
     * <p>
     * Can be any value.
     * </p>
     * <p>
     * Has getter and setter.
     * </p>
     */
    private XREFont font;

    /**
     * <p>
     * The color used to draw the text. Defaults to black (#FF000000).
     * </p>
     * <p>
     * Can be any value.
     * </p>
     * <p>
     * Has getter and setter.
     * </p>
     */
    private int color = Color.BLACK;

    /**
     * <p>
     * The text size, in pixels. Defaults to 12.
     * </p>
     * <p>
     * Can be any value.
     * </p>
     * <p>
     * Has getter and setter.
     * </p>
     */
    private int size = DEFAULT_TEXT_SIZE;

    /**
     * <p>
     * The value indicating whether to display a blinking underscore character at the end of the text resource.
     * </p>
     * <p>
     * Can be any value.
     * </p>
     * <p>
     * Has getter and setter.
     * </p>
     */
    private boolean blinkingCursor;

    /**
     * <p>
     * The amount of vertical spacing between lines of text, measured in pixels.
     * </p>
     * <p>
     * Can be any value.
     * </p>
     * <p>
     * Has getter and setter.
     * </p>
     */
    private int leading;

    /**
     * Represents document margin of text resource.
     * <p>
     * AndroidAssembly3 new field with getter and setter.
     */
    private double documentMargin;

    /**
     * <p>
     * Creates instance of {@link XREText} class.
     * </p>
     */
    public XREText() {
        // empty constructor
    }

    /**
     * <p>
     * Retrieves the text to be displayed by the resource.
     * </p>
     *
     * @return the text to be displayed by the resource
     */
    public String getText() {
        return text;
    }

    /**
     * <p>
     * Sets the text to be displayed by the resource.
     * </p>
     *
     * @param text the text to be displayed by the resource
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * <p>
     * Retrieves the font resource to be used to display the text.
     * </p>
     *
     * @return the font resource to be used to display the text
     */
    public XREFont getFont() {
        return font;
    }

    /**
     * <p>
     * Sets the font resource to be used to display the text.
     * </p>
     *
     * @param font the font resource to be used to display the text
     */
    public void setFont(XREFont font) {
        this.font = font;
    }

    /**
     * <p>
     * Retrieves the color used to draw the text.
     * </p>
     *
     * @return the color used to draw the text
     */
    public int getColor() {
        return color;
    }

    /**
     * <p>
     * Sets the color used to draw the text.
     * </p>
     *
     * @param color the color used to draw the text
     */
    public void setColor(int color) {
        this.color = color;
    }

    /**
     * <p>
     * Retrieves the text size, in pixels.
     * </p>
     *
     * @return the text size, in pixels
     */
    public int getSize() {
        return size;
    }

    /**
     * <p>
     * Sets the text size, in pixels.
     * </p>
     *
     * @param size the text size, in pixels
     */
    public void setSize(int size) {
        this.size = size;
    }

    /**
     * <p>
     * Retrieves the value indicating whether to display a blinking underscore character at the end of the text
     * resource.
     * </p>
     *
     * @return the value indicating whether to display a blinking underscore character at the end of the text resource
     */
    public boolean isBlinkingCursor() {
        return blinkingCursor;
    }

    /**
     * <p>
     * Sets the value indicating whether to display a blinking underscore character at the end of the text resource.
     * </p>
     *
     * @param blinkingCursor the value indicating whether to display a blinking underscore character at the end of the
     * text resource
     */
    public void setBlinkingCursor(boolean blinkingCursor) {
        this.blinkingCursor = blinkingCursor;
    }

    /**
     * <p>
     * Retrieves the amount of vertical spacing between lines of text, measured in pixels.
     * </p>
     *
     * @return the amount of vertical spacing between lines of text, measured in pixels
     */
    public int getLeading() {
        return leading;
    }

    /**
     * <p>
     * Sets the amount of vertical spacing between lines of text, measured in pixels.
     * </p>
     *
     * @param leading the amount of vertical spacing between lines of text, measured in pixels
     */
    public void setLeading(int leading) {
        this.leading = leading;
    }

    /**
     * Gets the document margin of text resource.
     *
     * @return the document margin of text resource
     */
    public double getDocumentMargin() {
        return documentMargin;
    }

    /**
     * Sets the document margin of text resource.
     *
     * @param documentMargin the document margin of text resource
     */
    public void setDocumentMargin(double documentMargin) {
        this.documentMargin = documentMargin;
    }

    /**
     * Retrieves the amount of vertical spacing between lines of text, measured in pixels.
     * <p>
     * AndroidAssembly3 new method
     *
     * @return the amount of vertical spacing between lines of text, measured in pixels
     */
    public int getNaturalLeading() {
        return leading;
    }

    /**
     * Retrieves the line height.
     * <p>
     * AndroidAssembly3 new method
     *
     * @return the amount of vertical spacing between lines of text, measured in pixels
     */
    public int getLineHeight() {
        // get paint object
        Paint paint = PaintersUtil.createPaint(this);
        float textSize = -paint.getFontMetrics().top + Math.max(getLeading(), paint.getFontMetrics().bottom);
        return (int) textSize;
    }
}
